/*
  HardwareSerial.h - Hardware serial library for Wiring
  Copyright (c) 2006 Nicholas Zambetti.  All right reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef HardwareSerial_h
#define HardwareSerial_h

#include "Configuration.h"
#include "util.h"

#include <inttypes.h>

#include <avr/pgmspace.h>
#include "Serial.h"
#include "print.h"


#define DEC 10

class HardwareSerial1// : public Print
{
	void printNumber(unsigned long, uint8_t);
	void printFloat(double, uint8_t);
		
public:
	HardwareSerial1(){}
    void begin(uint16_t br){ USART1_begin(br); }
    void end(){ USART1_end(); }
    uint8_t available(void){ return USART1_available(); }
    uint8_t read(void) { return USART1_read_byte(); }
    void flush(void){ USART1_flush_rx(); }
    void write(uint8_t b){ USART1_write_byte(b); }
	
    //using Print::write; // pull in write(str) and write(buf, size) from Print
	void print(char c) { this->write(c); }
	void print(const char[]);
	void print(uint8_t ui) { this->write(ui); };
	void print(int n){ print((long) n); }
	void print(unsigned int n){ print((unsigned long) n); }
	void print(long);
	void print(unsigned long n){ printNumber(n, 10);}
	void print(long, int);
	void print(double n){ printFloat(n, 2); }
	
	void println(void) { this->write('\r'); this->write('\n'); }
	void println(char c) { print(c); println(); }
	void println(const char ar[]) { print(ar); println(); }
	void println(uint8_t ui) { print(ui); println(); }
	
	void println(int i ){ print(i); println(); }
	void println(unsigned int ui){ print(ui); println(); }
	void println(long l){ print(l); println(); }
	void println(unsigned long ul){ print(ul); println(); }
	
	void println(long l, int i){ print (l, i); println(); }
	void println(double d){ print(d); println(); }

	//------------------------------------------------
	//Print a String from Flash to Serial (save RAM)
	//------------------------------------------------
	void print_P(PGM_P s);
	void println_P(PGM_P s) { print_P(s); println(); }
};

extern HardwareSerial1 Serial;

#endif
